//
//  GuideHeardView.m
//  ZhiHuiLiJiang
//
//  Created by work on 2018/11/15.
//  Copyright © 2018年 王雅鹏. All rights reserved.
//导览页tabviewHeadView-热门景点-市民热议

#import "GuideHeardView.h"
#import "BYHomeTopCarouselModel.h"
#import "BYGuideHeardCell.h"//热门景点-市民热议的瀑布流cell

@implementation GuideHeardView
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self addView];
        self.ImageMdelarray = [[NSMutableArray alloc]init];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
-(void)addView{
    [self.contentView addSubview:self.HScorll];
    [self.contentView addSubview:self.ScorllBottomView];
    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.Btn];
    [self.contentView addSubview:self.collectioneView];
    [self.contentView addSubview:self.twoTitleLabel];
    [self.contentView addSubview:self.twoBtn];
    [self.HScorll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.top.mas_equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(KSCREEWIDTH, 130));
    }];
    [self.ScorllBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.top.mas_equalTo(self.HScorll.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(KSCREEWIDTH, 4));
    }];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(10);
        make.top.mas_equalTo(self.ScorllBottomView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.mas_equalTo(self.imageView.mas_right).offset(10);
        make.centerY.mas_equalTo(self.imageView.mas_centerY);
    }];
    [self.Btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-10);
        make.centerY.mas_equalTo(self.imageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    [self.collectioneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(9);
        make.left.mas_equalTo(self.mas_left);
        make.size.mas_equalTo(CGSizeMake(KSCREEWIDTH, 90));
    }];
    [self.twoTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(10);
        make.top.mas_equalTo(self.collectioneView.mas_bottom).offset(16);
    }];
    [self.twoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-10);
        make.centerY.mas_equalTo(self.twoTitleLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
}
-(SDCycleScrollView *)HScorll{
    if (!_HScorll) {
        _HScorll = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, 0, 0) delegate:nil placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _HScorll.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _HScorll.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
        _HScorll.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _HScorll.delegate = self;
        _HScorll.currentPageDotImage = [UIImage imageNamed:@"轮播长条"];
        _HScorll.pageDotImage = [UIImage imageNamed:@"轮播圆点"];
        _HScorll.pageControlDotSize  = CGSizeMake(20, 5);
    }
    return _HScorll;
}
-(UICollectionView *)collectioneView{
    if (!_collectioneView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //设置collectionView滚动方向
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//        layout.collectionView.contentSize = CGSizeMake(KSCREEWIDTH *2, 0);
        //    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        _collectioneView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, BY_Height(450)+BY_StatusBar_H, 0, BY_ScreenHeight - BY_Height(450) - BY_StatusBar_H - BY_Bot_H) collectionViewLayout:layout];
        _collectioneView.showsVerticalScrollIndicator = NO;
        _collectioneView.backgroundColor =  [UIColor clearColor];
        //3.注册collectionViewCell
        //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
            [self.collectioneView registerClass:[BYGuideHeardCell class] forCellWithReuseIdentifier:@"BYGuideHeardCell"];
        //    [self.collectioneView registerClass:[MyTwoCollectionViewCell class] forCellWithReuseIdentifier:@"MyTwoCollectionViewCell"];
        
        //注册headerView  此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致  均为reusableView
        _collectioneView.showsHorizontalScrollIndicator= NO;
        //4.设置代理
//        _collectioneView.contentSize =CGSizeMake(KSCREEWIDTH *2, 0);
        _collectioneView.delegate = self;
        _collectioneView.dataSource = self;
    }
    return _collectioneView;
}
-(UIButton *)Btn{
    if (!_Btn) {
        _Btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_Btn setTitle:@"查看更多" forState:UIControlStateNormal];
        _Btn.titleLabel.font = H13;
        [_Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_Btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Btn;
}
-(UILabel *)imageView{
    if (!_imageView) {
        _imageView = [[UILabel alloc]init];
        _imageView.text = @"热";
        _imageView.textColor  =[UIColor whiteColor];
        _imageView.font = H12;
        _imageView.textAlignment = NSTextAlignmentCenter;
        _imageView.layer.masksToBounds = YES;
        _imageView.layer.cornerRadius = 9;
        _imageView.backgroundColor = RGBA(39, 199, 174, 1);
    }
    return _imageView;
}
-(UIView *)ScorllBottomView{
    if (!_ScorllBottomView) {
        _ScorllBottomView = [[UIView alloc]init];
        _ScorllBottomView.backgroundColor = RGBA(226, 226, 226, 1);
    }
    return _ScorllBottomView;
}
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"市民热议";
        _titleLabel.font = H14;
    }
    return _titleLabel;
}
-(UILabel *)twoTitleLabel{
    if (!_twoTitleLabel) {
        _twoTitleLabel = [[UILabel alloc]init];
        _twoTitleLabel.font = H14;
    }
    return _twoTitleLabel;
}
-(UIButton *)twoBtn{
    if (!_twoBtn) {
        _twoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_twoBtn setTitle:@"查看更多" forState:UIControlStateNormal];
        _twoBtn.titleLabel.font = H13;
        [_twoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_twoBtn addTarget:self action:@selector(twobtnclick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _twoBtn;
}
-(void)btnclick{
    if (self.delegate  && [self.delegate respondsToSelector:@selector(moreBtn)]) {
        [self.delegate moreBtn];
    }
}
-(void)twobtnclick{
    if (self.delegate  && [self.delegate respondsToSelector:@selector(twomoreBtn)]) {
        [self.delegate twomoreBtn];
    }
}
-(void)setHMdelarray:(NSMutableArray *)HMdelarray{
    _HMdelarray = HMdelarray;
    NSMutableArray *urlArrM = [NSMutableArray arrayWithCapacity:_HMdelarray.count];
    for (BYHomeTopCarouselModel *model in _HMdelarray) {
        [urlArrM addObject:model.img];
    }
    NSArray *imagesURLStrings = urlArrM.copy;
    _HScorll.imageURLStringsGroup = imagesURLStrings;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{//点击了轮播图
    if (self.clickRotationIconView) {
        self.clickRotationIconView(index);
    }
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    BYGuideHeardCell *cell = (BYGuideHeardCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"BYGuideHeardCell" forIndexPath:indexPath];
     cell.model = self.ImageMdelarray[indexPath.row];
    return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.ImageMdelarray.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{//设置每个item的尺寸
    return CGSizeMake(BY_Width(248), BY_Width(164));
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{//设置每个item的UIEdgeInsets
    return UIEdgeInsetsMake(BY_Height(30), BY_Width(24), BY_Height(14), BY_Width(24));
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{//设置每个item水平间距
    if (section ==0) {
        return BY_Width(10);
    }
    return BY_Height(12);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{//设置每个item垂直间距
    if (section ==0) {
        return BY_Height(10);
    }
    return BY_Height(12);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    BYcitizenModel *model = self.ImageMdelarray[indexPath.row];
    if (self.delegate && [self.delegate respondsToSelector:@selector(tapImage:)]) {
        [self.delegate tapImage:model.material_uid];
    }
}


@end
